package BoardGameToTreeIntegration;

import java.io.File;
import java.io.IOException;

import org.eclipse.emf.ecore.EObject;
import org.moflon.moca.txt.parser.TxtParserAdapter;
import org.moflon.util.TranslatorHelper;
import org.moflon.util.eMoflonEMFUtil;

import BoardGame.BoardGamePackage;
import Moca.CodeAdapter;
import Moca.MocaFactory;
import MocaTree.Folder;
import MocaTree.MocaTreePackage;
import TGGLanguage.TGGLanguagePackage;
import TGGLanguage.TripleGraphGrammar;
import TGGLanguage.algorithm.ApplicationTypes;
public class TGGMainBack {
	public static void main(String[] args) throws IOException {
		
		//Perform Text to Tree
		
		CodeAdapter codeAdapter = MocaFactory.eINSTANCE.createCodeAdapter();
		codeAdapter.getParser().add(new TxtParserAdapter());
		Folder tree = codeAdapter.parse(new File("instances/text/"));

	    // Save tree to file
	    eMoflonEMFUtil.saveModel(MocaTreePackage.eINSTANCE, tree, "instances/tree/tree.xmi");
		
		TranslatorHelper helper = new TranslatorHelper();
		helper.setInputModel(MocaTreePackage.eINSTANCE,
				"./instances/tree/tree.xmi");
		helper.setOutputModel(BoardGamePackage.eINSTANCE,
				"./instances/model/board.xmi");
		helper.setCorrModel(BoardGameToTreeIntegrationPackage.eINSTANCE,
				"./instances/CorrespondenceModel.xmi");
		helper.setDirection(ApplicationTypes.BACKWARD);
		helper.setStaticAnalysis("../BoardGameToTreeIntegration/"
				+ "model/BoardGameToTreeIntegration.gen.sma.xmi");
		try {
			helper.integrate();
		} catch (Exception e) {
			e.printStackTrace();
			
		}
		
		EObject created = helper.getOutputRoot();
		
		eMoflonEMFUtil.saveModel(TGGLanguagePackage.eINSTANCE, helper.getTranslationProtocol(), "./instances/protocol.xmi");
		
		System.out.println(created);
	}
}